﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using Lib.Web.Mvc.JQuery.JqGrid.DataAnnotations;
using System.ComponentModel;
using Northwind.Model;
using System.Web.Routing;
using System.Web.Mvc;
using Lib.Web.Mvc.JQuery.JqGrid;

namespace jqGrid.DungDepTrai.Models
{
    public class EmployeeViewModel
    {
        #region Properties
        [ScaffoldColumn(false)]
        public int Id { get; set; }

        [JqGridColumnSortable(false)]
        [JqGridColumnFormatter("$.photoFormatter", UnFormatter = "$.photoUnFormatter")]
        [JqGridColumnLayout(Alignment = JqGridAlignments.Center, Width = 35)]
        [JqGridColumnEditable(true, EditType = JqGridColumnEditTypes.File)]
        public string Photo { get; private set; }

        [StringLength(25)]
        [JqGridColumnSortable(true)]
        [DisplayName("Title of courtesy")]
        [JqGridColumnEditable(true, EditType = JqGridColumnEditTypes.Text)]
        public string TitleOfCourtesy { get; set; }

        [Required]
        [StringLength(10)]
        [DisplayName("First name")]
        [JqGridColumnSortable(true)]
        [JqGridColumnEditable(true, EditType = JqGridColumnEditTypes.Text)]
        public string FirstName { get; set; }

        [Required]
        [StringLength(20)]
        [DisplayName("Last name")]
        [JqGridColumnSortable(true)]
        [JqGridColumnEditable(true, EditType = JqGridColumnEditTypes.Text)]
        public string LastName { get; set; }

        [StringLength(30)]
        [JqGridColumnSortable(true)]
        [JqGridColumnEditable(true, EditType = JqGridColumnEditTypes.Text)]
        public string Title { get; set; }

        [AllowHtml]
        [JqGridColumnSortable(false)]
        [JqGridColumnLayout(Width = 450)]
        [JqGridColumnEditable(true, EditType = JqGridColumnEditTypes.TextArea)]
        public string Notes { get; set; }
        #endregion

        #region Constructors
        public EmployeeViewModel()
        { }

        public EmployeeViewModel(Employee employee)
        {
            this.Id = employee.Id;
            this.TitleOfCourtesy = employee.TitleOfCourtesy;
            this.FirstName = employee.FirstName;
            this.LastName = employee.LastName;
            this.Title = employee.Title;
            this.Notes = employee.Notes;

            RouteValueDictionary photoUrlRouteData = new RouteValueDictionary();
            photoUrlRouteData["controller"] = "Home";
            photoUrlRouteData["action"] = "EmployeePhoto";
            photoUrlRouteData["id"] = employee.Id;
            Photo = RouteTable.Routes.GetVirtualPathForArea(HttpContext.Current != null ? HttpContext.Current.Request.RequestContext : null, null, photoUrlRouteData).VirtualPath;
        }
        #endregion
    }
}